<?php

namespace App\Models;

class BarsClassModel
{
    public static function barsClassList($conn){
        $typeSql="SELECT `id`, `bid`, `name`,`img`, `time`, `status` FROM `bars_class` where `status` = 1 and `id` in(SELECT `cid` FROM `bars_goods` where 1 group by `cid`) and `show` =1 order by sort desc";
        return $conn->readConn($typeSql,true);
    }
    /**
     * 添加轮播图
     * entry
     * return array
     * */
    public static function insertBarsClass($conn,$BarsClassExample){
        $fundsSql ="INSERT INTO `bars_class`(`name`, `img`, `show`, `sort`) VALUES ('$BarsClassExample->name','$BarsClassExample->img','$BarsClassExample->show','$BarsClassExample->sort')";
        return $conn->executeConn($fundsSql);
    }
    /**
     * 修改轮播图可添加字段
     * entry BannerExample
     * return int
     * */
    public static function upBarsClassInside($conn,$BarsClassExample){
        $joinSql="";
        if($BarsClassExample->bid !=null){
            $joinSql.=" `bid` = '$BarsClassExample->bid',";
        }
        if($BarsClassExample->name !=null){
            $joinSql.=" `name` = '$BarsClassExample->name',";
        }
        if($BarsClassExample->show !=null){
            $joinSql.=" `show` = '$BarsClassExample->show',";
        }
        if($BarsClassExample->sort !=null){
            $joinSql.=" `sort` = '$BarsClassExample->sort',";
        }
        if($BarsClassExample->img !=null){
            $joinSql.=" `img` = '$BarsClassExample->img',";
        }
        if($BarsClassExample->status !=null){
            $joinSql.=" `status` = $BarsClassExample->status,";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `bars_class` SET $innerJoin WHERE `id` = '$BarsClassExample->id'";
            return $conn->executeConn($upUserSql);
        }
    }
}